package com.ljh.mboxvidoserver.console.shoptype.service.impl;

import com.ljh.mboxvidoserver.console.shoptype.dao.ShopTypeRepository;
import com.ljh.mboxvidoserver.console.shoptype.entity.ShopType;
import com.ljh.mboxvidoserver.console.shoptype.service.ShopTypeService;
import com.mysql.jdbc.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class ShopTypeServiceImpl implements ShopTypeService {

    @Autowired
    private ShopTypeRepository shopTypeRepository;

    @Override
    public Page<ShopType> findList(ShopType shopType, Pageable pageable) {
        if(StringUtils.isNullOrEmpty(shopType.getTypeName())){
            return shopTypeRepository.findAll(pageable);
        }else{
            return shopTypeRepository.findAllLikeTypeName(shopType.getTypeName(),pageable);
        }
    }

    @Override
    public ShopType findOne(ShopType shopType) {
        return shopTypeRepository.getOne(shopType.getId());
    }

    @Override
    public ShopType insertOne(ShopType shopType) {
        return shopTypeRepository.save(shopType);
    }

    @Override
    public void deleteOne(ShopType shopType) {
        shopTypeRepository.delete(shopType);
    }

    @Override
    public ShopType updateOne(ShopType shopType) {
        return shopTypeRepository.save(shopType);
    }
}
